import 'package:ysy_flutter_mvvm_yuanxuan/api/HttpConfig.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/api/NetUtils.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/bean/detail/AddCartEntity.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/bean/subitorder/SubitOrderEntity.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/helper/AppProperties.dart';
import 'dart:convert' as convert;

/// -------------------- 登录  start------------------ ///

//登录
Future login(String name, String password) async {
  var map = {"telephone": name, "password": password};
  return await postHttp(HttpConfig.URL_USER_LOGIN, params: map);
}

//快捷登录
Future loginQuick(String name, String code) async {
  var map = {"telephone": name, "code": code};
  return await postHttp(HttpConfig.URL_USER_LOGIN_QUICK, params: map);
}

//注册
Future register(String telephone, String authCode, String  password) async {
  var map = {"telephone": telephone, "authCode": authCode,"password":password};
  return await postHttp(HttpConfig.URL_USER_REGISTER, params: map);
}

//获取验证码
//templateCode   短信类型（1  login:登录,2  register:注册,3 update:修改密码，4 other:其他）
Future smsVerCode(String telephone,int type) async {
  String typeStr="other";
  if(int==1){
    typeStr="login";
  }else if(int==2){
    typeStr="register";
  }else if(int==3){
    typeStr="other";
  }
  var map = {"telephone": telephone, "templateCode": typeStr};
  var params = {"sign":getSendVerCodeSignature(map)};
  params.addAll(map);
  return await postHttp(HttpConfig.URL_USER_GET_VER_CODE, params: params);
}

/// -------------------- 登录  end------------------ ///


/// -------------------- 首页  start------------------ ///

//首页 推荐 头部
Future recommend() async {
  var map = {"type": "1"};
  return await getHttp(HttpConfig.URL_HOME_CONTENT,params: map);
}

//首页 关注 头部
Future attention() async {
  var map = {"type": "2"};
  return await getHttp(HttpConfig.URL_HOME_CONTENT,params: map);
}

//首页 分类
Future recommendCategory() async {
  return await getHttp(HttpConfig.URL_HOME_GOODS_CATEGORY_LIST);
}

//首页 商品列表
Future recommendGoodsList(int? type,int pageSize,int pageNum) async {
  var map = {"pageSize": pageSize,"pageNum":pageNum};
  if(type!=null) map["type"]=type;
  return await getHttp(HttpConfig.URL_HOME_REC_GOODS_LIST,params: map);
}

//首页 关注  列表
Future attentionList(int pageSize,int pageNum) async {
  var map = {"pageSize": pageSize,"pageNum":pageNum};
  return await getHttp(HttpConfig.URL_HOME_FOL_SHOP_LIST,params: map);
}

/// -------------------- 首页  end------------------ ///

/// -------------------- 工作台  start------------------ ///

//工作台
Future myInfoData() async {
  return await getHttp(HttpConfig.URL_MY_INFO);
}

/// -------------------- 工作台  end------------------ ///
///
/// -------------------- 创作   start------------------ ///

//短视频
Future shortVideoList(int pageSize,int pageNum) async {
  var map = {"pageSize": pageSize,"pageNum":pageNum};
  return await getHttp(HttpConfig.URL_SHORT_VIDEO_SSO_LIST,params: map);
}
/// -------------------- 创作   end------------------ ///
///
/// -------------------- 商品详情   start------------------ ///

//商品详情
Future goodsDetails(String productId) async {
  var map = {"productId": productId};
  return await getHttp(HttpConfig.URL_COMMODITY_DATETAIL,params: map);
}

//收藏
Future goodsDetailsCollection(String productId) async {
  var map = {"productId": productId};
  return await getHttp(HttpConfig.URL_COMMODITY_COLLECTIBLE,params: map);
}

//喜欢
Future goodsDetailsLike(String productId) async {
  var map = {"productId": productId};
  return await getHttp(HttpConfig.URL_COMMODITY_LIKE,params: map);
}

//加入购物车
Future addCart(AddCartEntity entity) async {
  return await postHttp(HttpConfig.URL_ADD_CART, body: convert.jsonEncode(entity.toJson()).toString());
  // return await getHttp(HttpConfig.URL_ADD_CART, params: entity.toJson());
}
/// -------------------- 商品详情   end------------------ ///
/// -------------------- 商品详情   start------------------ ///

//商品详情
Future cartShoppingList() async {
  return await getHttp(HttpConfig.URL_CART_LIST);
}

/// -------------------- 商品详情   end------------------ ///
/// -------------------- 确认订单   start------------------ ///

//提交订单
Future subitOrder(List<SubitOrderEntity> list) async {
  return await postHttp(HttpConfig.URL_ORDER_CONFIRMORDER,body: list);
}

/// -------------------- 确认订单   end------------------ ///